// 创建Vuex
import Vue from "vue";
import Vuex, { Store } from "vuex";
// 使用Vuex
Vue.use(Vuex);
// 创建一个store并暴露出去
export default new Store({
  // 定义发送请求和一些逻辑上的判断
  actions: {
    qishu({ commit, state }, value) {
      if (state.sum % 2) {
        commit("JIA", value);
      }
    },
    dengyixia({ commit }, value) {
      setTimeout(() => {
        commit("JIA", value);
      });
    },
  },
  // 定义纯函数
  mutations: {
    JIA(state, value) {
      state.sum += value;
    },
    JIAN(state, value) {
      state.sum -= value;
    },
  },
  // 定义初始化的数据
  state: {
    sum: 1,
    school: "youdiandaxue",
    address: "昌平",
  },
  getters: {
    bigSum(state) {
      return (state.sum * 10);
    },
    bigSchool(state) {
      return state.school.toUpperCase();
    },
  },
});
